package demo1.dao.impl;

import demo1.dao.UserDao;
import demo1.dao.mapper.UserMapper;
import demo1.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    JdbcTemplate tmp;

    @Override
    public User selectByName(String name) {
        String sql="select id,name,pass from t_user where name=?";
        List<User>list= tmp.query(sql,new UserMapper(),name);

        return list.isEmpty()?null:list.get(0);
    }

    @Override
    public void insert(User u) {
        tmp.update("insert into t_user(name,pass) values(?,?)",u.getName(),u.getPass());

    }
}
